<template>
	<view>
		<InvoiceNavbarSwiper ref="navbarSwiper" :navbarList="navbarList" :curNavbar="curNavbar" :height="'88rpx'" :dateList="dateList"
		 @handleChooseNavbar="handleChooseNavbar" @handleScrolltolower="handleScrolltolower" @handleRefresherrefresh="handleRefresherrefresh"></InvoiceNavbarSwiper>
	</view>
</template>

<script>
	import InvoiceNavbarSwiper from '@/components/user/invoice-navbarSwiper.vue'
	export default {
		components: {
			InvoiceNavbarSwiper
		},
		data() {
			return {
				navbarList: [{
						name: '机场大巴',
						alias: 'bus'
					},
					{
						name: '拼车',
						alias: 'carpool'
					},
					{
						name: '包车',
						alias: 'chartered'
					},
					{
						name: '租车',
						alias: 'rent'
					},
				],
				curNavbar: {
					name: '机场大巴',
					alias: 'bus'
				},
				curSwiperIndex: 0, // navbar 的index
				busList: [],
				carpoolList: [],
				charteredList: [],
				rentList: [],
				page: {
					pageNum: 0,
					totalPageNum: 0,
					pageSize: 10,
				},
			};
		},
		computed: {
			dateList() {
				return [this.busList, this.carpoolList, this.charteredList, this.rentList]
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			// 获取机场大巴数据
			getList() {
				this.page.pageNum = 1
				if (this.curSwiperIndex == 0) {
					this.$http.get(this.$api.getBusOrderList + '?type=9&pageSize=' + this.page.pageSize + '&pageNum=' + this.page.pageNum)
						.then(res => {
							if (res.code === 200) {
								this.page.totalPageNum = res.data.total
								this.$refs.navbarSwiper.stopPullDownRefresh()
								this.busList = res.data.result
							}
						})
				} else if (this.curSwiperIndex == 1) {
					this.$http.get(this.$api.getCarpoolOrderList + '?type=9&pageSize=' + this.page.pageSize + '&pageNum=' + this.page.pageNum)
						.then(res => {
							if (res.code === 200) {
								this.page.totalPageNum = res.data.total
								this.$refs.navbarSwiper.stopPullDownRefresh()
								this.carpoolList = res.data.result
							}
						})
				} else if (this.curSwiperIndex == 2) {
					this.$http.get(this.$api.getCharteredOrderList + '?type=9&pageSize=' + this.page.pageSize + '&pageNum=' + this.page.pageNum)
						.then(res => {
							if (res.code === 200) {
								this.page.totalPageNum = res.data.total
								this.$refs.navbarSwiper.stopPullDownRefresh()
								this.charteredList = res.data.result
							}
						})
				} else if (this.curSwiperIndex == 3) {
					this.$http.get(this.$api.getRentOrderList + '?type=9&pageSize=' + this.page.pageSize + '&pageNum=' + this.page.pageNum)
						.then(res => {
							if (res.code === 200) {
								this.page.totalPageNum = res.data.total
								this.$refs.navbarSwiper.stopPullDownRefresh()
								this.rentList = res.data.result
							}
						})
				}
			},
			// 改变navbar
			handleChooseNavbar(item, i) {
				this.curSwiperIndex = i
				this.curNavbar = item
				this.getList()
			},
			// 上拉加载更多
			handleScrolltolower(item, i) {
				this.curSwiperIndex = i
				let totalPage = Math.ceil(this.page.totalPageNum / this.page.pageSize)
				if (this.page.pageNum >= totalPage) return
				this.page.pageNum++
				this.getList()
			},
			handleRefresherrefresh(item, i) {
				this.curSwiperIndex = i
				this.page.pageNum = 1
				this.getList()

			},

		}
	}
</script>

<style lang="scss" scoped>

</style>
